package org.xsk.structure.stack;

import lombok.Data;

/**
 * 数组实现栈
 */
@Data
public class Stack {
    private int maxSize;
    private long[] stackArray;
    private int top;

    public Stack(int maxSize) {
        this.maxSize = maxSize;
        stackArray = new long[maxSize];
        top = -1;
    }

    public void push(long i){
        stackArray[++top] = i;
    }

    public long pop(){
        return stackArray[top--];
    }

    public long peek(){
        return stackArray[top];
    }

    public boolean isEmpty(){
        return top == -1;
    }

    public boolean isFull(){
        return top == maxSize - 1;
    }
    // i++ + i++ + i++ + i++
    // 0 + 1++ = 1
    // 0 + 1++ + 2++ + 3++ = ?
    // 0 + 1 + 2 + 3 = 6
}
